using System;
using UnityEngine;

namespace HCP
{
	[AddComponentMenu("HCP/Element")]
	public abstract class Sticky : MonoBehaviour
	{
		public string Id
		{
			get
			{
				return "HCP-" + ((!this.m_bUnsafe) ? string.Empty : "UNSAFE-") + this.m_sUniqueGuid;
			}
		}

		public string Path
		{
			get
			{
				this.CalculatePath();
				return this.m_sPath;
			}
		}

		public string Name
		{
			get
			{
				this.CalculateName();
				return this.m_sName;
			}
		}

		private void Reset()
		{
			this.m_bUnsafe = false;
			this.GenerateUId();
			this.CalculatePath();
			this.CalculateName();
		}

		private void GenerateUId()
		{
			if (string.IsNullOrEmpty(this.m_sUniqueGuid))
			{
				this.m_sUniqueGuid = Guid.NewGuid().ToString();
			}
		}

		private void CalculatePath()
		{
			this.m_sPath = Element.ConstructXPath(base.transform);
		}

		private void CalculateName()
		{
			this.m_sName = base.name;
		}

		private void Start()
		{
			if (base.GetComponents<Sticky>().Length > 1)
			{
				throw new Exception("HCP.Sticky Error - You cannot attach more than one Sticky component to a single game object.");
			}
			this.GenerateUId();
			this.CalculatePath();
			this.CalculateName();
		}

		[Sticky]
		[SerializeField]
		protected string m_sUniqueGuid;

		[SerializeField]
		[HideInInspector]
		protected bool m_bUnsafe = true;

		[Sticky]
		[NonSerialized]
		protected string m_sPath;

		[Sticky]
		[NonSerialized]
		protected string m_sName;
	}
}
